package com.hangjiang.gulidear.web;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.googlecode.sslplugin.annotation.Secured;
import com.hangjiang.gulidear.model.Comment;
import com.hangjiang.gulidear.model.Project;
import com.hangjiang.gulidear.model.User;
import com.hangjiang.gulidear.service.CommentService;
import com.hangjiang.gulidear.service.ProjectService;
@Controller("commentAction")
@Scope("prototype")
@Secured
public class CommentAction {
	private int tatalScore;
	private int sheduleScore;
	private int qualityScore;
	private int communicationScore;
	private String commentContent;
	private CommentService commentService;
	private Date commentTime;
	private String projectId;
	private String userId;
	 
	
	private ProjectService projectService;

	public String doAdd() {
		Comment entity = new Comment();
		entity.setTatalScore(tatalScore);
		entity.setSheduleScore(sheduleScore);
		entity.setQualityScore(qualityScore);
		entity.setCommunicationScore(communicationScore);
		entity.setCommentContent(commentContent);
		entity.setCommentTime(new Date());
		Project project = projectService.findById(projectId);
		User user = (User) ServletActionContext.getContext().getSession().get("user");
		entity.setProject(project);
		entity.setUser(user);
		commentService.save(entity);
		return "show";
	}
  public String commentPage(){
	  
	  User user=(User) ServletActionContext.getContext().getSession().get("user");
	  String projectId = (String) ServletActionContext.getContext().getSession().get("projectId");
	  ServletActionContext.getRequest().setAttribute("user", user);
	  ServletActionContext.getRequest().setAttribute("projectId",projectId );
	  return "comment";
  }
	
 public String showCommentList(){
	 String projectId = (String)ServletActionContext.getContext().getSession().get("projectId");
	// String projectId =project.getProjectId();
	 String projectName = projectService.findById(projectId).getProjName();
	 
	 List<Comment> comments = commentService.findCommentsByProjectId(projectId);
	 
	 ServletActionContext.getRequest().setAttribute("comments",comments );
	 ServletActionContext.getRequest().setAttribute("projectName",projectName);
	 return "commentList";
 }
	public int getTatalScore() {
		return tatalScore;
	}

	public void setTatalScore(int tatalScore) {
		this.tatalScore = tatalScore;
	}

	public int getSheduleScore() {
		return sheduleScore;
	}

	public void setSheduleScore(int sheduleScore) {
		this.sheduleScore = sheduleScore;
	}

	public int getQualityScore() {
		return qualityScore;
	}

	public void setQualityScore(int qualityScore) {
		this.qualityScore = qualityScore;
	}

	public int getCommunicationScore() {
		return communicationScore;
	}

	public void setCommunicationScore(int communicationScore) {
		this.communicationScore = communicationScore;
	}

	public String getCommentContent() {
		return commentContent;
	}

	public void setCommentContent(String commentContent) {
		this.commentContent = commentContent;
	}

	public Date getCommentTime() {
		return commentTime;
	}

	public void setCommentTime(Date commentTime) {
		this.commentTime = commentTime;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	
	@Resource(name = "commentService")
	public void setCommentservice(CommentService commentService) {
		this.commentService = commentService;
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}

  @Resource(name="projectService")
	public void setProjectService(ProjectService projectService) {
		this.projectService = projectService;
	}

}
